package com.zhuss.core.role;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.core.role.CareRolePermissionListBo;
import com.zhuss.bean.bo.core.role.CareRoleUserListBo;
import com.zhuss.bean.bo.core.role.DetailRoleBo;
import com.zhuss.bean.bo.core.role.SearchRoleBo;
import com.zhuss.bean.vo.core.permission.ListPermissionTreeBean;
import com.zhuss.bean.vo.core.role.CareRolePermissionListVo;
import com.zhuss.bean.vo.core.role.CareRoleUserListVo;
import com.zhuss.common.AbstractBo;
import com.zhuss.common.ListVo;
import com.zhuss.common.ReadService;
import com.zhuss.core.processor.PermissionRead;
import com.zhuss.core.processor.RolePermissionRead;
import com.zhuss.core.processor.RoleRead;
import com.zhuss.core.processor.UserRead;
import com.zhuss.core.processor.UserRoleRead;
import com.zhuss.exception.OceanException;


/**
 * 角色查询service（基本查询）
 * @author zhushanshuo
 * @Date 2019-12-13 15:59
 *
 */
@Component("roleReadService")
public class RoleReadService implements ReadService<Object, Object> {
	
	@Autowired
	@Qualifier("roleRead")
	private RoleRead roleRead;
	
	@Autowired
	@Qualifier("permissionRead")
	private PermissionRead permissionRead;
	
	@Autowired
	@Qualifier("rolePermissionRead")
	private RolePermissionRead rolePermissionRead;
	
	@Autowired
	@Qualifier("userRoleRead")
	private UserRoleRead userRoleRead;
	
	@Autowired
	@Qualifier("userRead")
	private UserRead userRead;
	
	/**
	 * 详情
	 */
	@Override
	public Object detail(Object param) throws OceanException {
		DetailRoleBo bo = (DetailRoleBo) param;
		Long roleId = bo.getRoleId();
		Object vo = roleRead.detail(roleId);
		return vo;
	}
	
	/**
	 * 列表
	 */
	@Override
	public Object list(Object param) {
		SearchRoleBo bo = (SearchRoleBo) param;
		Object result = roleRead.list(bo);
		return result;
	}
	
	
	/**
	 * 角色的权限树列表
	 * @param bo
	 * @return
	 * @throws OceanException 
	 */
	@SuppressWarnings("unchecked")
	public Object careRolePermissionList(CareRolePermissionListBo bo) throws OceanException {
		
		Long roleId = bo.getRoleId();
		CareRolePermissionListVo result = new CareRolePermissionListVo();
		result.setPermissionIdList((List<Long>)rolePermissionRead.listPermissionId(roleId));
		result.setPermissionTreeList((List<ListPermissionTreeBean>)permissionRead.listPermissionTreeBean(null));
		return result;
	}
	
	
	/**
	 * 角色的用户列表
	 * @param bo
	 * @return
	 * @throws OceanException 
	 */
	@SuppressWarnings("unchecked")
	public Object careRoleUserList(CareRoleUserListBo bo) throws OceanException {
		
		Long roleId = bo.getRoleId();
		
		CareRoleUserListVo result = new CareRoleUserListVo();
		result.setUserIdList((List<Long>)userRoleRead.listUserId(roleId));
		result.setUserList((List<ListVo>)userRead.listUser());
		return result;
	}
	
	
	/**
	 * 角色列表
	 * @param bo
	 * @return
	 * @throws OceanException 
	 */
	public Object roleList(AbstractBo bo) throws OceanException {
		
		Object result = roleRead.listRole();
		return result;
	}
	
	
	
	
	
}

